{config_load "layout.conf"} 
<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8" />
		<meta name="description" content="{$content->meta['description']}">
		<meta name="keywords" content="{$content->meta['keywords']}">	
		<title>{$content->meta['title']} | {$site['title']|default:""}</title>

		<script src="public/js/jquery-1.6.2.min.js" type="text/javascript"></script>
		<script src="public/js/jquery-ui-1.8.16.custom.min.js" type="text/javascript"></script>
		
		
		<!--[if lte IE 7]>
		<link rel="stylesheet" href="http://public/css/anythingslider-ie.css" type="text/css" media="screen" />
		<![endif]-->	
		<link rel="stylesheet" href="public/css/redmond/jquery-ui-1.8.16.custom.css" type="text/css" media="all" />
		{has_access url="content/update"}
			<script src="public/js/tiny_mce/tiny_mce.js" type="text/javascript"></script>
			<script src="public/js/jqueryFileTree.js" type="text/javascript"></script>
			<link href="public/css/jqueryFileTree.css" rel="stylesheet" type="text/css" media="screen" />
			
			<script src="public/js/jquery.contextMenu.js" type="text/javascript"></script>
			<link href="public/css/jquery.contextMenu.css" rel="stylesheet" type="text/css" media="all" />
			
			<script src="public/js/jquery.upload-1.0.2.js" type="text/javascript"></script>
		
			<link rel="stylesheet" href="public/css/editmode.css" type="text/css" media="all" />
			
			{literal}
			<script type="text/javascript">
				$(function() {
						
						$("#editcontent" ).dialog( "destroy" );

						
						$(".buttoneditcontent").click(function(){
						
							$( "#tabs" ).tabs();
							$( "#editcontent" ).dialog( {
								modal: true,
								width: '960',
								height: '500',
								buttons: {
									"Valider": function() {
										var result = true;
			{/literal}
				{if $currentRole=="USER"}
					{foreach $conf->values['options']['modules'] as $def}
					   if(result) result = {$def}_validate();
					{/foreach}
				{elseif $currentRole=="ADMIN"}
					{foreach $conf->values['content.def'] as $def}
					   if(result) result = {$def@key}_validate();
					{/foreach}
				{/if}
										
										if(result){
											var params = new Object();
											params['content_name'] = "{$content->content_name}";
			{literal}
											$("#editcontent")
												.find(':input') // Find all the input elements under those.
												.each(function(i) {
													if (params[this.name]){
														params[this.name].push(this.value);
													}
													else{
														params[this.name] = new Array(this.value);
													}
												});
											$.ajax({
												type: 'POST',
												url: 'content/update',
												data: params,
												success: function(retour){
													//$("#debug").html(retour);
													location.reload();
													$("#editcontent").dialog( "close" );
												}
											});
										}
									},
									"Annuler": function() {
										var result = true;
			{/literal}
				{if $currentRole=="USER"}
					{foreach $conf->values['options']['modules'] as $def}
					    if(result) result = {$def}_close();
					{/foreach}
				{elseif $currentRole=="ADMIN"}
					{foreach $conf->values['content.def'] as $def}
					    if(result) result = {$def@key}_close();
					{/foreach}
				{/if}
			{literal}
										if(result){
											$( this ).dialog( "close" );
										}
									}
								},
								open: function(event, ui) { 
			{/literal}
				{if $currentRole=="USER"}
					{foreach $conf->values['options']['modules'] as $def}
					   {$def}_open();
					{/foreach}
				{elseif $currentRole=="ADMIN"}
					{foreach $conf->values['content.def'] as $def}
					   {$def@key}_open();
					{/foreach}
				{/if}
			{literal}
									
								}
							} );
						})
					});
			</script>			
			{/literal}
		{/has_access}
		{block name=head_slider}{/block}
		{block name=head}{/block}
	</head>
	<body>
		{block name=body}{/block}
		{has_access url="content/update"}
			<div id="debug"></div>
			<div id="editcontent" title="Modifier le contenu">
				<div id="tabs">
					{if $currentRole=="USER"}
						<ul>
						{foreach $conf->values['options']['modules'] as $def}
						   <li><a href="#tabs-{$def@index}">{#$def#}</a></li>
						{/foreach}
						</ul>
						{foreach $conf->values['options']['modules'] as $def}
						<div id="tabs-{$def@index}" class="{$def}">
							{include "def.{$def}.tpl"}
						</div>
						{/foreach}
					{elseif $currentRole=="ADMIN"}
						<ul class="paneladmin">
						{foreach $conf->values['content.def'] as $def}
						   <li><a href="#tabs-{$def@index}">{#$def@key#}</a></li>
						{/foreach}
						</ul>
						{foreach $conf->values['content.def'] as $def}
						<div id="tabs-{$def@index}" class="{$def@key}">
							{include "def.{$def@key}.tpl"}
						</div>
						{/foreach}
					{/if}
				</div>

			</div>
		{/has_access}
		{include file="google_analytics.tpl"}
	</body>
</html>
